#include <algorithm>
#include <cstdio>
#define lowbit(x) (x & (-x))

const int N = 1e5 + 5;
int n, p[N], val[N], ans[N], hash[N];
int e_cnt, heads[N];

struct Edge {
  int v, nxt;
} e[N << 1];

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
}

inline void modify(int x, int v) {
  while (x <= *hash + 1) { val[x] += v, x += lowbit(x); }
}

inline int query(int x) {
  int res = 0;
  while (x) { res += val[x], x -= lowbit(x); }
  return res;
}

void solve(int x) {
  int tmp = query(p[x] - 1);
  for (int i = heads[x]; i; i = e[i].nxt) { solve(e[i].v); }
  ans[x] = query(p[x] - 1) - tmp;
  modify(p[x], 1);
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P3605 [USACO17JAN]Promotion Counting P.in", "r", stdin);
  freopen("P3605 [USACO17JAN]Promotion Counting P.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i]), hash[i] = p[i];
  std::sort(hash + 1, hash + n + 1);
  *hash = std::unique(hash + 1, hash + n + 1) - hash - 1;
  for (int i = 1; i <= n; ++i)
    p[i] = *hash - (std::lower_bound(hash + 1, hash + n + 1, p[i]) - hash) + 1;
  for (int i = 2, fa; i <= n; ++i) {
    scanf("%d", &fa);
    add(fa, i);
  }
  solve(1);
  for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
  return 0;
}